/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: agent-java
 * Description: Agent written in java language
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 */
package ru.ffind.agent.dao;

import com.google.common.collect.Lists;
import java.util.List;
import java.util.Map;

/**
 * Abstract implementation for processing files in batch.
 *
 * @author Rage Steel
 */
public abstract class AbstractBatch implements Batch {

    protected List<Map<String, Object>> fileArgs = Lists.newArrayList();

    /**
     * {@inheritDoc}
     */
    @Override
    public final int executeBatch() {
        int filesCount = fileArgs.size();
        if (filesCount > 0) {
            doExecute(ArgUtils.toBatchArgs(fileArgs));
        }
        fileArgs = null;
        return filesCount;
    }

    /**
     * Run executing batch.
     * 
     * @param batch
     */
    protected abstract void doExecute(Map<String, Object>[] batch);

}
